﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WinFromMediaPlayerDemo.Interface;

namespace WinFromMediaPlayerDemo.Provider
{
    public enum MessageType
    {
        Information=0,
        Error = 1,
        Warning = 2
    }
    public abstract class MessageProviderBase:IMessageProvider
    {
        public string Caption { get; set; }

        public string Content { get; set; }

        public MessageType? MessageType { get; set; }

        public abstract void Show(string content, string caption = "系统提示", MessageType messageType = Provider.MessageType.Error);
    }

    public class CustomeMessageProvider : MessageProviderBase
    {
        public CustomeMessageProvider(Form parentForm)
        {
            this.ParentWindows = parentForm;
        }
        public Form ParentWindows { get; set; }
        public override void Show(string content, string caption = "系统提示", MessageType messageType = Provider.MessageType.Error)
        {
            this.Content = content;
            this.MessageType = messageType;
            this.MessageType = messageType;

            MessageBoxIcon defaultIcon = MessageBoxIcon.Information;
            string messageTypeStr = Enum.GetName(typeof(MessageType), MessageType);
            Enum.TryParse<MessageBoxIcon>(messageTypeStr, out defaultIcon);
            ParentWindows.Invoke(new Action(() =>
            {
                MessageBox.Show(ParentWindows, Content, Caption, MessageBoxButtons.OK, defaultIcon);
            }));
            
        }
    }
}
